package cn.bingo.yunsj.service;

import cn.bingo.yunsj.common.Param;
import cn.bingo.yunsj.controller.model.LinkEmployeeSendModel;
import link.message.client.MessageClient;
import link.message.client.SendMessageResult;
import link.message.client.content.complex.Action;
import link.message.client.content.complex.ComplexMessageContent;
import link.message.client.content.complex.ComplexMessageContentItem;
import link.message.client.content.complex.ComplexMessageType;
import link.message.client.messager.PersonMessageReceiver;
import org.springframework.stereotype.Service;

@Service
public class LinkSendService {

    /**
     * 图文消息发送（主要使用）
     */
    public void LinkMessageSend(LinkEmployeeSendModel sendModel){
        if(sendModel==null){
            return;
        }
        MessageClient messageClient = new MessageClient(
                Param.EMB_SERVICE_URL,
                Param.APP_ID,
                Param.SECRET_KEY);

        ComplexMessageContent complexTextMessage = new ComplexMessageContent(Param.BRIEF
                , ComplexMessageType.IMAGE_TEXT);
        ComplexMessageContentItem contentItem1 = new ComplexMessageContentItem(Param.PICTURE_WORDS,
                Param.CARDS_PICTURE_URL,
                Action.instanceAsOpenHtml(sendModel.getCardHtml()));
        complexTextMessage.addMessageContentItem(contentItem1);

        SendMessageResult result = messageClient.sendSingleMessage(complexTextMessage
                , new PersonMessageReceiver(sendModel.getAccount(), sendModel.getUserName()));

    }
}
